package com.wingsboat;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author wangzhong
 * @description: TODO 5健键盘
 * @date 2024/7/19 22:04
 */
public class Test1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] nums = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int result =0;
        int temp = 0;
        boolean isSelected = false;
        for (int num : nums) {
            switch(num){
                case 5: // ctl-a
                    if(result>0) isSelected = true;
                    break;
                case 1: // a
                    if(isSelected) result = 0;
                    result++;
                    isSelected = false;
                    break;
                case 2: // ctl-c
                    if(isSelected) temp = result;
                    break;
                case 3: // ctl-x
                    if(isSelected){
                        temp = result;
                        result = 0;
                        isSelected = false;
                    }
                    break;
                case 4: // ctl-v
                    if(isSelected) result = 0;
                    result = temp + result;
                    isSelected = false;
                    break;

            }
        }
        System.out.println(result);
    }
}
